package com.example.webmodule.util;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class HostnameToIpUtil {
    /**
     * 将主机名转换为 IP 地址
     *
     * @param hostname 主机名
     * @return IP 地址
     */
    public static String convertToIp(String hostname) {
        try {
            InetAddress inetAddress = InetAddress.getByName(hostname);
            return inetAddress.getHostAddress();
        } catch (UnknownHostException e) {
            e.printStackTrace();
            return hostname; // 如果解析失败，返回原始主机名
        }
    }
}
